package cn.jbit.nio;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.net.InetSocketAddress;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;

/**
 * 源码学院只为培养优秀的bat程序员而生
 *
 * @author 学员张在成
 * @data 2020/8/6
 */
public class TestSendFile {

    public static void main(String[] args) throws IOException {

        File  file=new File("D:/person.txt");
        RandomAccessFile raf=new RandomAccessFile(file,"rw");
        FileChannel  fileChannel=raf.getChannel();
        SocketChannel socketChannel=SocketChannel.open(new InetSocketAddress("",1234));
        fileChannel.transferTo(0,fileChannel.size(),socketChannel);  //零拷贝

    }
}
